package com.xiyu.service.repository.elder.info;

import com.xiyu.service.model.elder.info.ElderInfo;
import com.xiyu.service.model.elder.info.ElderInfoTable;
import com.xiyu.service.vo.elder.elderInfo.ElderInfoQueryInput;
import org.babyfish.jimmer.spring.repository.JRepository;
import org.babyfish.jimmer.Page;
import org.springframework.util.StringUtils;

public interface ElderInfoRepository extends JRepository<ElderInfo, Long> {
    ElderInfoTable elderInfoTable = ElderInfoTable.$;

    default Page<ElderInfo> query(ElderInfoQueryInput inputVO){
        return sql().createQuery(elderInfoTable)
                .whereIf(StringUtils.hasText(inputVO.getName()), () -> elderInfoTable.name().like(inputVO.getName()))
                .whereIf(inputVO.getSex() != null, elderInfoTable.sex().eq(inputVO.getSex()))
                .orderBy(elderInfoTable.id().desc())
                .select(elderInfoTable)
                .fetchPage(inputVO.getPageNo() - 1, inputVO.getPageSize());
    }

}